<?php

namespace App\Exceptions;

use Exception;
use Illuminate\Support\Facades\Log;
use Throwable;

class WechatException extends Exception
{
    public function __construct($message = "", $code = 0, Throwable $previous = null)
    {
        parent::__construct($message, $code, $previous);
    }

    public function report( )
    {
        $request = request();

        $parameters = $request->all(); // 获取所有请求参数

        $path = $request -> getPathInfo();

        $response = [
          'code' => $this->getCode(),
          'message' => $this->getMessage()
        ];

        $log = json_encode([
            'path'  => $path,
            'params' => $parameters,
            'response' => $response,
        ], 259);

        Log::channel('wechat') -> error($log);
    }
}
